import pygame
from pygame.locals import *
from State import *
from Gui import *

class GuiTest(State):
   def __init__(self, screen):
      State.__init__(self, 'GuiTest')
      self.screen = screen
      self.gui = Gui()
      font = pygame.font.get_default_font()
      window = Window((10, 120, 355, 260), 'Simple window with Textbox widget', font)
      vscroll = VScroll((340, 35, 10, 160))
      button = Button((280, 230, 60, 18), "send", font, 12)
      self.entry = Entry(10, 230, 20, "", font, 13)
      button.onClick.append(self.on_test_btn_click)
      window.add(button)
      window.add(vscroll)
      window.add(self.entry)
      self.textbox = TextBox(10, 35, 11, 27, pygame.font.get_default_font(), 12)
      self.textbox.add_line("hello world!")
      window.add(self.textbox)
      self.gui.add(window)
      self.gui.add(Dialog(200,100))
      self.dragging = None
      self.focus = None
      
   def update(self):
      mpos = pygame.mouse.get_pos()
      if self.gui.getClick(mpos):
         self.gui.update()
      else: 
         for event in pygame.event.get():
            if event.type == pygame.QUIT: self.run = False
            elif event.type == KEYDOWN:
               if event.key == K_ESCAPE:
                  self.run = False
            elif event.type == KEYUP:
               pass

   def draw(self):
      self.screen.fill((0,0,0))
      self.gui.draw_debug()
      self.gui.draw()
      pygame.display.flip()
      
   def on_test_btn_click(self):
      self.textbox.add_line("clicked a test button!")
      
